<?php
session_start();
include '../dbconnect.php';
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" href="../css/styles.css">
	
    <title>搜索</title>
    <style>
        .container {
            width: 1100px;
            margin: 0 auto;
        }
        .search {
            display: inline-block;
            vertical-align: top;
            width: 23%; /* 25% - 2% for margins */
            margin: 1%;
            text-align: center;
        }
        .search img {
            width: 100%;
            height: auto;
        }
        .search a {
            text-decoration: none;
            color: black;
            font-size: 19px;
        }
        .search a:hover {
            text-decoration: underline;
        }
        .search .name {
            font-weight: bold;
			color:#fff;
            margin-top: 10px;
        }
        .search .price {
            color: red;
            font-size: 18px;
        }
    </style>
</head>
<body>
<!-- 顶部开始 -->

<!-- 头部开始 -->
<?php include '../common/header.php'; ?>
<!-- 头部结束 -->

<!-- 主体开始 -->
<div class="module-content">
    <div class="services">
        <h1>Our Services</h1>
        <div class="service-list">
            <?php
            include '../dbconnect.php';

            if (isset($_REQUEST['kw'])) {
                $keywords = $_REQUEST['kw'];
                // 包含关键词，进行搜索
                $sql = "SELECT * FROM services WHERE SERVICE_NAME LIKE '%{$keywords}%' AND IS_DELETE = 0";
                $result = $conn->query($sql);

                if ($result->num_rows > 0) {
                    while ($row = $result->fetch_assoc()) {
                        ?>
                        <div class="service-item">
                            <img src="<?php echo $row['SERVICE_PICTURE']; ?>" alt="<?php echo $row['SERVICE_NAME']; ?>">
                            <div class="service-content">
                                <h2><?php echo $row['SERVICE_NAME']; ?></h2>
                                <p><?php echo $row['SERVICE_DESCRIPTION']; ?></p>
                                <a href="6_appointment.php?service_id=<?php echo $row['SERVICE_ID']; ?>" class="button">Make an Appointment for Consultation</a>
                            </div>
                        </div>
                        <?php
                    }
                } else {
                    echo "<p>No services found for the keyword: {$keywords}</p>";
                }
            } else {
                // 不包含关键词，显示全部服务
                $sql = "SELECT * FROM services WHERE IS_DELETE = 0";
                $result = $conn->query($sql);
                if ($result->num_rows > 0) {
                    while ($row = $result->fetch_assoc()) {
                        ?>
                        <div class="service-item">
                            <img src="<?php echo $row['SERVICE_PICTURE']; ?>" alt="<?php echo $row['SERVICE_NAME']; ?>">
                            <div class="service-content">
                                <h2><?php echo $row['SERVICE_NAME']; ?></h2>
                                <p><?php echo $row['SERVICE_DESCRIPTION']; ?></p>
                                <a href="6_appointment.php?service_id=<?php echo $row['SERVICE_ID']; ?>" class="button">Make an Appointment for Consultation</a>
                            </div>
                        </div>
                        <?php
                    }
                } else {
                    echo "<p>No services available.</p>";
                }
            }
            $conn->close();
            ?>
        </div>
    </div>
</div>
<!-- 主体结束 -->

<!-- 页脚开始 -->
<!-- footer.php -->
<?php include '../common/footer.php'; ?>
<!-- 页脚结束 -->
</body>
</html>

<?php
include '../db_close.php';
?>